

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Teams &mdash; O365  documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />

  
      <script src="../_static/jquery.js?v=5d32c60e"></script>
      <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
      <script src="../_static/documentation_options.js?v=5929fcd5"></script>
      <script src="../_static/doctools.js?v=9bcbadda"></script>
      <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Utils" href="utils.html" />
    <link rel="prev" title="Tasks" href="tasks.html" />
    <link href="../_static/css/style.css" rel="stylesheet" type="text/css">

</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html">
            
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../overview.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../getting_started.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../usage.html">Detailed Usage</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="connection.html">Protocols</a></li>
<li class="toctree-l2"><a class="reference internal" href="connection.html#resources">Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="account.html">Account</a></li>
<li class="toctree-l2"><a class="reference internal" href="account.html#account-class-and-modularity">Account Class and Modularity</a></li>
<li class="toctree-l2"><a class="reference internal" href="addressbook.html">Address Book</a></li>
<li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendar</a></li>
<li class="toctree-l2"><a class="reference internal" href="directory.html">Directory and Users</a></li>
<li class="toctree-l2"><a class="reference internal" href="excel.html">Excel</a></li>
<li class="toctree-l2"><a class="reference internal" href="group.html">Group</a></li>
<li class="toctree-l2"><a class="reference internal" href="mailbox.html">Mailbox</a></li>
<li class="toctree-l2"><a class="reference internal" href="onedrive.html">OneDrive</a></li>
<li class="toctree-l2"><a class="reference internal" href="planner.html">Planner</a></li>
<li class="toctree-l2"><a class="reference internal" href="sharepoint.html">Sharepoint</a></li>
<li class="toctree-l2"><a class="reference internal" href="tasks.html">Tasks</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Teams</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#presence">Presence</a></li>
<li class="toctree-l3"><a class="reference internal" href="#chat">Chat</a></li>
<li class="toctree-l3"><a class="reference internal" href="#team">Team</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="utils.html">Utils</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api.html">O365 API</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">O365</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../usage.html">Detailed Usage</a></li>
      <li class="breadcrumb-item active">Teams</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/usage/teams.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
        <a href="tasks.html" class="btn btn-neutral float-left" title="Tasks" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="utils.html" class="btn btn-neutral float-right" title="Utils" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  </div>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="teams">
<h1>Teams<a class="headerlink" href="#teams" title="Link to this heading"></a></h1>
<p>Teams enables the communications via Teams Chat, plus Presence management</p>
<p>These are the scopes needed to work with the <code class="docutils literal notranslate"><span class="pre">Teams</span></code> classes.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Raw Scope</p></th>
<th class="head"><p>Included in Scope Helper</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Channel.ReadBasic.All</p></td>
<td><p>—</p></td>
<td><p>To read basic channel information</p></td>
</tr>
<tr class="row-odd"><td><p>ChannelMessage.Read.All</p></td>
<td><p>—</p></td>
<td><p>To read channel messages</p></td>
</tr>
<tr class="row-even"><td><p>ChannelMessage.Send</p></td>
<td><p>—</p></td>
<td><p>To send messages to a channel</p></td>
</tr>
<tr class="row-odd"><td><p>Chat.Read</p></td>
<td><p>—</p></td>
<td><p>To read users chat</p></td>
</tr>
<tr class="row-even"><td><p>Chat.ReadWrite</p></td>
<td><p>—</p></td>
<td><p>To read users chat and send chat messages</p></td>
</tr>
<tr class="row-odd"><td><p>Presence.Read</p></td>
<td><p>presence</p></td>
<td><p>To read users presence status</p></td>
</tr>
<tr class="row-even"><td><p>Presence.Read.All</p></td>
<td><p>—</p></td>
<td><p>To read any users presence status</p></td>
</tr>
<tr class="row-odd"><td><p>Presence.ReadWrite</p></td>
<td><p>—</p></td>
<td><p>To update users presence status</p></td>
</tr>
<tr class="row-even"><td><p>Team.ReadBasic.All</p></td>
<td><p>—</p></td>
<td><p>To read only the basic properties for all my teams</p></td>
</tr>
<tr class="row-odd"><td><p>User.ReadBasic.All</p></td>
<td><p>users</p></td>
<td><p>To only read basic properties from users of my organization (User.Read.All requires administrator consent)</p></td>
</tr>
</tbody>
</table>
<section id="presence">
<h2>Presence<a class="headerlink" href="#presence" title="Link to this heading"></a></h2>
<p>Assuming an authenticated account.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Retrieve logged-in user&#39;s presence</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span>
<span class="n">account</span> <span class="o">=</span> <span class="n">Account</span><span class="p">((</span><span class="s1">&#39;app_id&#39;</span><span class="p">,</span> <span class="s1">&#39;app_pw&#39;</span><span class="p">))</span>
<span class="n">teams</span> <span class="o">=</span> <span class="n">account</span><span class="o">.</span><span class="n">teams</span><span class="p">()</span>
<span class="n">presence</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">get_my_presence</span><span class="p">()</span>

<span class="c1"># Retrieve another user&#39;s presence</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">account</span><span class="o">.</span><span class="n">directory</span><span class="p">()</span><span class="o">.</span><span class="n">get_user</span><span class="p">(</span><span class="s2">&quot;john@doe.com&quot;</span><span class="p">)</span>
<span class="n">presence2</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">get_user_presence</span><span class="p">(</span><span class="n">user</span><span class="o">.</span><span class="n">object_id</span><span class="p">)</span>
</pre></div>
</div>
<p>To set a users status or preferred status:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Set user&#39;s presence</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">O365.teams</span><span class="w"> </span><span class="kn">import</span> <span class="n">Activity</span><span class="p">,</span> <span class="n">Availability</span><span class="p">,</span> <span class="n">PreferredActivity</span><span class="p">,</span> <span class="n">PreferredAvailability</span>

<span class="n">status</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">set_my_presence</span><span class="p">(</span><span class="n">CLIENT_ID</span><span class="p">,</span> <span class="n">Availability</span><span class="o">.</span><span class="n">BUSY</span><span class="p">,</span> <span class="n">Activity</span><span class="o">.</span><span class="n">INACALL</span><span class="p">,</span> <span class="s2">&quot;1H&quot;</span><span class="p">)</span>

<span class="c1"># or set User&#39;s preferred presence (which is more likely the one you want)</span>

<span class="n">status</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">set_my_user_preferred_presence</span><span class="p">(</span><span class="n">PreferredAvailability</span><span class="o">.</span><span class="n">OFFLINE</span><span class="p">,</span> <span class="n">PreferredActivity</span><span class="o">.</span><span class="n">OFFWORK</span><span class="p">,</span> <span class="s2">&quot;1H&quot;</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="chat">
<h2>Chat<a class="headerlink" href="#chat" title="Link to this heading"></a></h2>
<p>Assuming an authenticated account.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Retrieve logged-in user&#39;s chats</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span>
<span class="n">account</span> <span class="o">=</span> <span class="n">Account</span><span class="p">((</span><span class="s1">&#39;app_id&#39;</span><span class="p">,</span> <span class="s1">&#39;app_pw&#39;</span><span class="p">))</span>
<span class="n">teams</span> <span class="o">=</span> <span class="n">account</span><span class="o">.</span><span class="n">teams</span><span class="p">()</span>
<span class="n">chats</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">get_my_chats</span><span class="p">()</span>

<span class="c1"># Then to retrieve chat messages and chat members</span>
<span class="k">for</span> <span class="n">chat</span> <span class="ow">in</span> <span class="n">chats</span><span class="p">:</span>
    <span class="k">if</span> <span class="n">chat</span><span class="o">.</span><span class="n">chat_type</span> <span class="o">!=</span> <span class="s2">&quot;unknownFutureValue&quot;</span><span class="p">:</span>
        <span class="n">message</span> <span class="o">=</span> <span class="n">chat</span><span class="o">.</span><span class="n">get_messages</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
        <span class="n">memberlist</span> <span class="o">=</span> <span class="n">chat</span><span class="o">.</span><span class="n">get_members</span><span class="p">()</span>


<span class="c1"># And to send a chat message</span>

<span class="n">chat</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">content</span><span class="o">=</span><span class="s2">&quot;Hello team!&quot;</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s2">&quot;text&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">Common commands for <code class="code docutils literal notranslate"><span class="pre">Chat</span></code> include <code class="code docutils literal notranslate"><span class="pre">.get_member()</span></code> and <code class="code docutils literal notranslate"><span class="pre">.get_message()</span></code></div>
</div>
</section>
<section id="team">
<h2>Team<a class="headerlink" href="#team" title="Link to this heading"></a></h2>
<p>Assuming an authenticated account.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Retrieve logged-in user&#39;s teams</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">O365</span><span class="w"> </span><span class="kn">import</span> <span class="n">Account</span>
<span class="n">account</span> <span class="o">=</span> <span class="n">Account</span><span class="p">((</span><span class="s1">&#39;app_id&#39;</span><span class="p">,</span> <span class="s1">&#39;app_pw&#39;</span><span class="p">))</span>
<span class="n">teams</span> <span class="o">=</span> <span class="n">account</span><span class="o">.</span><span class="n">teams</span><span class="p">()</span>
<span class="n">my_teams</span> <span class="o">=</span> <span class="n">teams</span><span class="o">.</span><span class="n">get_my_teams</span><span class="p">()</span>

<span class="c1"># Then to retrieve team channels and messages</span>
<span class="k">for</span> <span class="n">team</span> <span class="ow">in</span> <span class="n">my_teams</span><span class="p">:</span>
    <span class="n">channels</span> <span class="o">=</span> <span class="n">team</span><span class="o">.</span><span class="n">get_channels</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">channel</span> <span class="ow">in</span> <span class="n">channels</span><span class="p">:</span>
        <span class="n">messages</span> <span class="o">=</span> <span class="n">channel</span><span class="o">.</span><span class="n">get_messages</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">channelmessage</span> <span class="ow">in</span> <span class="n">messages</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="n">channelmessage</span><span class="p">)</span>


<span class="c1"># To send a message to a team channel</span>
<span class="n">channel</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="s2">&quot;Hello team&quot;</span><span class="p">)</span>

<span class="c1"># To send a reply to a message</span>
<span class="n">channelmessage</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="s2">&quot;Hello team leader&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">Common commands for <code class="code docutils literal notranslate"><span class="pre">Teams</span></code> include <code class="code docutils literal notranslate"><span class="pre">.create_channel()</span></code>, <code class="code docutils literal notranslate"><span class="pre">.get_apps_in_channel()</span></code> and <code class="code docutils literal notranslate"><span class="pre">.get_channel()</span></code></div>
<div class="line">Common commands for <code class="code docutils literal notranslate"><span class="pre">Team</span></code> include <code class="code docutils literal notranslate"><span class="pre">.get_channel()</span></code></div>
<div class="line">Common commands for <code class="code docutils literal notranslate"><span class="pre">Channel</span></code> include <code class="code docutils literal notranslate"><span class="pre">.get_message()</span></code></div>
<div class="line">Common commands for <code class="code docutils literal notranslate"><span class="pre">ChannelMessage</span></code> include <code class="code docutils literal notranslate"><span class="pre">.get_replies()</span></code> and <code class="code docutils literal notranslate"><span class="pre">.get_reply()</span></code></div>
</div>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="tasks.html" class="btn btn-neutral float-left" title="Tasks" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="utils.html" class="btn btn-neutral float-right" title="Utils" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2025, alejcas.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>